home *** CD-ROM | disk | FTP | other *** search
/ The Utilities Experience / The Utilities Experience - Volume 1.iso / software / misc / o-z / x-windows / gs262 / gxcmap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-30  |  15.9 KB  |  519 lines

  1. /* Copyright (C) 1992, 1993 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* gxcmap.c */
  20. /* Color mapping and conversion for Ghostscript */
  21. #include "gx.h"
  22. #include "gserrors.h"
  23. #include "gscspace.h"
  24. #include "gxarith.h"
  25. #include "gxfrac.h"
  26. #include "gxlum.h"
  27. #include "gxcolor.h"
  28. #include "gxdevice.h"
  29. #include "gzcolor.h"
  30. #include "gzstate.h"
  31.  
  32. #ifdef AMIGA
  33. extern void gx_render_gray(frac, gx_device_color *, const gs_state *);
  34. extern void gx_render_rgb(frac, frac, frac, gx_device_color *, const gs_state *);
  35. #endif
  36.  
  37. /* Brought back from a later release.... */
  38. #define color_set_pure(pdc, color)\
  39.   ((pdc)->color1 = (pdc)->color2 = (color), (pdc)->halftone_level = 0)
  40.  
  41. /* Convert a frac to a gx_color_value. */
  42. /* This is needed because map_rgb_color still uses gx_color_value. */
  43. #define _cv_bits (sizeof(gx_color_value) * 8)
  44. #define frac2cv(fr)\
  45.   ( ((fr) << (_cv_bits - frac_bits)) +\
  46.     ((fr) >> (frac_bits * 2 - _cv_bits)) )
  47. #define cv2frac(cv) ((frac)((cv) >> (_cv_bits - frac_bits)))
  48.  
  49. /* Note: the color model conversion algorithms are taken from */
  50. /* Rogers, Procedural Elements for Computer Graphics, pp. 401-403. */
  51.  
  52. /* ------ Conversion between HSB and RGB ------ */
  53.  
  54. /* Convert RGB to HSB. */
  55. void
  56. color_rgb_to_hsb(floatp r, floatp g, floatp b, float hsb[3])
  57. {    frac red = float2frac(r), green = float2frac(g), blue = float2frac(b);
  58. #define rhue hsb[0]
  59. #define rsat hsb[1]
  60. #define rbri hsb[2]
  61.     if ( red == green && green == blue )
  62.        {    rhue = 0;    /* arbitrary */
  63.         rsat = 0;
  64.         rbri = r;    /* pick any one */
  65.        }
  66.     else
  67.        {    /* Convert rgb to hsb */
  68.         frac V, Temp;
  69.         long diff, H;
  70.         V = (red > green ? red : green);
  71.         if ( blue > V ) V = blue;
  72.         Temp = (red > green ? green : red);
  73.         if ( blue < Temp ) Temp = blue;
  74.         diff = V - Temp;
  75.         if ( V == red )
  76.             H = (green - blue) * frac_1_long / diff;
  77.         else if ( V == green )
  78.             H = (blue - red) * frac_1_long / diff + 2 * frac_1_long;
  79.         else /* V == blue */
  80.             H = (red - green) * frac_1_long / diff + 4 * frac_1_long;
  81.         if ( H < 0 ) H += 6 * frac_1_long;
  82.         rhue = H / (frac_1 * 6.0);
  83.         rsat = diff / (float)V;
  84.         rbri = frac2float(V);
  85.        }
  86. #undef rhue
  87. #undef rsat
  88. #undef rbri
  89. }
  90.  
  91. /* Convert HSB to RGB. */
  92. void
  93. color_hsb_to_rgb(floatp hue, floatp saturation, floatp brightness, float rgb[3])
  94. {    if ( saturation == 0 )
  95.        {    rgb[0] = rgb[1] = rgb[2] = brightness;
  96.        }
  97.     else
  98.        {    /* Convert hsb to rgb. */
  99.         /* We rely on the fact that the product of two */
  100.         /* fracs fits into an unsigned long. */
  101.         floatp h6 = hue * 6;
  102.         ulong V = float2frac(brightness);    /* force arithmetic to long */
  103.         frac S = float2frac(saturation);
  104.             int I = (int)h6;
  105.         ulong F = float2frac(h6 - I);        /* ditto */
  106.         /* M = V*(1-S), N = V*(1-S*F), K = V*(1-S*(1-F)) = M-N+V */
  107.         frac M = V * (frac_1_long - S) / frac_1_long;
  108.         frac N = V * (frac_1_long - S * F / frac_1_long) / frac_1_long;
  109.         frac K = M - N + V;
  110.         frac R, G, B;
  111.         switch ( I )
  112.            {
  113.         default: R = V; G = K; B = M; break;
  114.         case 1: R = N; G = V; B = M; break;
  115.         case 2: R = M; G = V; B = K; break;
  116.         case 3: R = M; G = N; B = V; break;
  117.         case 4: R = K; G = M; B = V; break;
  118.         case 5: R = V; G = M; B = N; break;
  119.            }
  120.         rgb[0] = frac2float(R);
  121.         rgb[1] = frac2float(G);
  122.         rgb[2] = frac2float(B);
  123. #ifdef DEBUG
  124. if ( debug_c('c') )
  125. {        dprintf7("[c]hsb(%g,%g,%g)->VSFI(%ld,%d,%ld,%d)->\n",
  126.              hue, saturation, brightness, V, S, F, I);
  127.         dprintf6("   RGB(%d,%d,%d)->rgb(%g,%g,%g)\n",
  128.              R, G, B, rgb[0], rgb[1], rgb[2]);
  129. }
  130. #endif
  131.        }
  132. }
  133.  
  134. /* ------ Color space conversion ------ */
  135.  
  136. /* Only 4 of the 6 conversions are implemented here; */
  137. /* the other 2 (Gray to RGB/CMYK) are trivial. */
  138. /* The CMYK to RGB algorithms specified by Adobe are, e.g., */
  139. /*    R = 1.0 - min(1.0, C + K)    */
  140. /* but we get much better results with */
  141. /*    R = (1.0 - C) * (1.0 - K)    */
  142.  
  143. /* Convert RGB to Gray. */
  144. frac
  145. color_rgb_to_gray(frac r, frac g, frac b, const gs_state *pgs)
  146. #ifndef AMIGA
  147. {    return (r * (unsigned long)lum_red_weight +
  148.         g * (unsigned long)lum_green_weight +
  149.         b * (unsigned long)lum_blue_weight +
  150.         (lum_all_weights / 2))
  151.         / lum_all_weights;
  152. }
  153. #else
  154. {    return ((frac)((r * (unsigned long)lum_red_weight +
  155.         g * (unsigned long)lum_green_weight +
  156.         b * (unsigned long)lum_blue_weight +
  157.         (lum_all_weights / 2))
  158.         / lum_all_weights));
  159. }
  160. #endif
  161.  
  162. /* Convert RGB to CMYK. */
  163. /* Note that this involves black generation and undercolor removal. */
  164. void
  165. color_rgb_to_cmyk(frac r, frac g, frac b, const gs_state *pgs,
  166.   frac cmyk[4])
  167. {    frac c = frac_1 - r, m = frac_1 - g, y = frac_1 - b;
  168.     frac k = (c < m ? min(c, y) : min(m, y));
  169.     /* The default UCR and BG functions are pretty arbitrary.... */
  170.     frac bg =
  171.         (pgs->black_generation == NULL ? frac_0 :
  172.          float2frac((*pgs->black_generation)(pgs, frac2float(k))));
  173.     signed_frac ucr =
  174.         (pgs->undercolor_removal == NULL ? frac_0 :
  175.          float2frac((*pgs->undercolor_removal)(pgs, frac2float(k))));
  176.     /* Adobe specifies, e.g., */
  177.     /*    C = max(0.0, min(1.0, 1 - R - UCR)) */
  178.     /* but in order to match our improved CMYK->RGB mapping, we use */
  179.     /*    C = max(0.0, min(1.0, 1 - R / (1 - UCR)) */
  180.     if ( ucr == frac_1 )
  181.         cmyk[0] = cmyk[1] = cmyk[2] = 0;
  182.     else
  183.     {    float denom = frac2float(frac_1 - ucr);    /* unscaled */
  184.         float v;
  185.         v = (float)frac_1 - r / denom;    /* unscaled */
  186.         cmyk[0] =
  187.           (is_fneg(v) ? frac_0 : v >= (float)frac_1 ? frac_1 : (frac)v);
  188.         v = (float)frac_1 - g / denom;    /* unscaled */
  189.         cmyk[1] =
  190.           (is_fneg(v) ? frac_0 : v >= (float)frac_1 ? frac_1 : (frac)v);
  191.         v = (float)frac_1 - b / denom;    /* unscaled */
  192.         cmyk[2] =
  193.           (is_fneg(v) ? frac_0 : v >= (float)frac_1 ? frac_1 : (frac)v);
  194.     }
  195.     cmyk[3] = bg;
  196.     if_debug7('c', "[c]RGB 0x%x,0x%x,0x%x -> CMYK 0x%x,0x%x,0x%x,0x%x\n",
  197.           r, g, b, cmyk[0], cmyk[1], cmyk[2], cmyk[3]);
  198. }
  199.  
  200. /* Convert CMYK to Gray. */
  201. frac
  202. color_cmyk_to_gray(frac c, frac m, frac y, frac k, const gs_state *pgs)
  203. {    frac not_gray = color_rgb_to_gray(c, m, y, pgs);
  204. #ifndef AMIGA
  205.     return (not_gray > frac_1 - k ?        /* gray + k > 1.0 */
  206.         frac_0 : frac_1 - (not_gray + k));
  207. #else
  208.     return ((frac)(not_gray > frac_1 - k ?        /* gray + k > 1.0 */
  209.         frac_0 : frac_1 - (not_gray + k)));
  210. #endif
  211. }
  212.  
  213. /* Convert CMYK to RGB. */
  214. void
  215. color_cmyk_to_rgb(frac c, frac m, frac y, frac k, const gs_state *pgs,
  216.   frac rgb[3])
  217. {    switch ( k )
  218.     {
  219.     case frac_0:
  220.         rgb[0] = frac_1 - c;
  221.         rgb[1] = frac_1 - m;
  222.         rgb[2] = frac_1 - y;
  223.         break;
  224.     case frac_1:
  225.         rgb[0] = rgb[1] = rgb[2] = frac_0;
  226.         break;
  227.     default:
  228.     {    ulong not_k = frac_1 - k;
  229.         /* Compute not_k * (frac_1 - v) / frac_1 efficiently. */
  230.         ulong prod;
  231. #define deduct_black(v)\
  232.   (prod = (frac_1 - (v)) * not_k,\
  233.    (prod + (prod >> frac_bits) + 1) >> frac_bits)
  234.         rgb[0] = deduct_black(c);
  235.         rgb[1] = deduct_black(m);
  236.         rgb[2] = deduct_black(y);
  237.     }
  238.     }
  239.     if_debug7('c', "[c]CMYK 0x%x,0x%x,0x%x,0x%x -> RGB 0x%x,0x%x,0x%x\n",
  240.           c, m, y, k, rgb[0], rgb[1], rgb[2]);
  241. }
  242.  
  243. /* ------ Device color rendering ------ */
  244.  
  245. private cmap_proc_gray(cmap_gray_halftoned);
  246. private cmap_proc_gray(cmap_gray_direct);
  247. private cmap_proc_gray(cmap_gray_to_rgb);
  248. private cmap_proc_gray(cmap_gray_to_cmyk);
  249. #define cmap_rgb_halftoned cmap_rgb_direct
  250. private cmap_proc_rgb(cmap_rgb_direct);
  251. private cmap_proc_rgb(cmap_rgb_to_gray);
  252. private cmap_proc_rgb(cmap_rgb_to_cmyk);
  253. #define cmap_cmyk_halftoned cmap_cmyk_direct
  254. private cmap_proc_cmyk(cmap_cmyk_direct);
  255. private cmap_proc_cmyk(cmap_cmyk_to_gray);
  256. private cmap_proc_cmyk(cmap_cmyk_to_rgb);
  257.  
  258. private const gx_color_map_procs
  259.     cmap_gray_few =
  260.         { cmap_gray_halftoned, cmap_rgb_to_gray, cmap_cmyk_to_gray },
  261.     cmap_gray_many =
  262.         { cmap_gray_direct, cmap_rgb_to_gray, cmap_cmyk_to_gray },
  263.     cmap_rgb_few =
  264.         { cmap_gray_to_rgb, cmap_rgb_halftoned, cmap_cmyk_to_rgb },
  265.     cmap_rgb_many =
  266.         { cmap_gray_to_rgb, cmap_rgb_direct, cmap_cmyk_to_rgb },
  267.     cmap_cmyk_few =
  268.         { cmap_gray_to_cmyk, cmap_rgb_to_cmyk, cmap_cmyk_halftoned },
  269.     cmap_cmyk_many =
  270.         { cmap_gray_to_cmyk, cmap_rgb_to_cmyk, cmap_cmyk_direct };
  271.  
  272. const gx_color_map_procs *cmap_procs_default = &cmap_gray_many;
  273.  
  274. private const gx_color_map_procs _ds *cmap_few[] = {
  275.     0, &cmap_gray_few, 0, &cmap_rgb_few, &cmap_cmyk_few
  276. };
  277.  
  278. private const gx_color_map_procs _ds *cmap_many[] = {
  279.     0, &cmap_gray_many, 0, &cmap_rgb_many, &cmap_cmyk_many
  280. };
  281.  
  282. /* Set the color mapping procedures in the graphics state. */
  283. void
  284. gx_set_cmap_procs(gs_state *pgs)
  285. {    gx_device *dev = gs_currentdevice(pgs);
  286.     pgs->cmap_procs =
  287.         ((gx_device_has_color(dev) ? dev->color_info.max_rgb :
  288.           dev->color_info.max_gray) >= 31 ? cmap_many : cmap_few)
  289.          [dev->color_info.num_components];
  290. }
  291.  
  292. /* Remap the color in the graphics state. */
  293. int
  294. gx_remap_color(gs_state *pgs)
  295. {    const gs_color_space *pcs = pgs->color_space;
  296.     return (*pcs->type->remap_color)(pgs->ccolor, pcs,
  297.                 pgs->dev_color, pgs);
  298. }
  299. /* Color remappers for the standard color spaces. */
  300. #define unit_frac(v)\
  301.   (ftemp = (v),\
  302.    (is_fneg(ftemp) ? frac_0 : ftemp >= 1.0 ? frac_1 : float2frac(ftemp)))
  303. int
  304. gx_remap_DeviceGray(const gs_client_color *pc, const gs_color_space *pcs,
  305.   gx_device_color *pdc, gs_state *pgs)
  306. {    float ftemp;
  307.     (*pgs->cmap_procs->map_gray)
  308.         (unit_frac(pc->paint.values[0]),
  309.          pdc, pgs);
  310.     return 0;
  311. }
  312. int
  313. gx_remap_DeviceRGB(const gs_client_color *pc, const gs_color_space *pcs,
  314.   gx_device_color *pdc, gs_state *pgs)
  315. {    float ftemp;
  316.     (*pgs->cmap_procs->map_rgb)
  317.         (unit_frac(pc->paint.values[0]),
  318.          unit_frac(pc->paint.values[1]),
  319.          unit_frac(pc->paint.values[2]),
  320.          pdc, pgs);
  321.     return 0;
  322. }
  323. int
  324. gx_remap_DeviceCMYK(const gs_client_color *pc, const gs_color_space *pcs,
  325.   gx_device_color *pdc, gs_state *pgs)
  326. {    float ftemp;
  327.     (*pgs->cmap_procs->map_cmyk)
  328.         (unit_frac(pc->paint.values[0]),
  329.          unit_frac(pc->paint.values[1]),
  330.          unit_frac(pc->paint.values[2]),
  331.          unit_frac(pc->paint.values[3]),
  332.          pdc, pgs);
  333.     return 0;
  334. }
  335. #undef unit_frac
  336.  
  337. /* Render Gray color. */
  338.  
  339. private void
  340. cmap_gray_direct(frac gray, gx_device_color *pdc, const gs_state *pgs)
  341. {    gx_device *dev = gs_currentdevice(pgs);
  342.     frac mgray = gx_map_color_frac(pgs, gray, gray);
  343.     gx_color_value cv_gray = frac2cv(mgray);
  344.     gx_color_index color =
  345.         (*dev->procs->map_rgb_color)(dev, cv_gray, cv_gray, cv_gray);
  346.     if ( color == gx_no_color_index )
  347.     {    gx_render_gray(mgray, pdc, pgs);
  348.         return;
  349.     }
  350.     color_set_pure(pdc, color);
  351. }
  352.  
  353. private void
  354. cmap_gray_halftoned(frac gray, gx_device_color *pdc, const gs_state *pgs)
  355. {    gx_render_gray(gx_map_color_frac(pgs, gray, gray), pdc, pgs);
  356. }
  357.  
  358. private void
  359. cmap_gray_to_rgb(frac gray, gx_device_color *pdc, const gs_state *pgs)
  360. {    (*pgs->cmap_procs->map_rgb)(gray, gray, gray, pdc, pgs);
  361. }
  362.  
  363. private void
  364. cmap_gray_to_cmyk(frac gray, gx_device_color *pdc, const gs_state *pgs)
  365. {    (*pgs->cmap_procs->map_cmyk)(frac_0, frac_0, frac_0, gray, pdc, pgs);
  366. }
  367.  
  368. /* Render RGB color. */
  369.  
  370. /*
  371.  * This code should test r == g and g == b and then use the gray
  372.  * rendering procedures.  The Adobe documentation allows this:
  373.  * conversion between color spaces occurs before the transfer function
  374.  * and halftoning.  However, output from FrameMaker (mis)uses the
  375.  * transfer function to provide the equivalent of indexed color;
  376.  * it requires the color components to be passed through unchanged.
  377.  * For this reason, we have to make the check after the transfer
  378.  * function rather than before.
  379.  */
  380.  
  381. private void
  382. cmap_rgb_direct(frac r, frac g, frac b, gx_device_color *pdc,
  383.   const gs_state *pgs)
  384. {    gx_device *dev = gs_currentdevice(pgs);
  385.     frac mred = gx_map_color_frac(pgs, r, red);
  386.     frac mgreen = gx_map_color_frac(pgs, g, green);
  387.     frac mblue = gx_map_color_frac(pgs, b, blue);
  388.     /* We make a test for direct vs. halftoned, rather than */
  389.     /* duplicating most of the code of this procedure. */
  390.     if ( dev->color_info.max_rgb >= 31 )
  391.     {    gx_color_index color =
  392.             (*dev->procs->map_rgb_color)(dev,
  393.                 frac2cv(mred), frac2cv(mgreen),
  394.                 frac2cv(mblue));
  395.         if ( color != gx_no_color_index )
  396.         {    color_set_pure(pdc, color);
  397.             return;
  398.         }
  399.     }
  400.     if ( mred == mgreen && mred == mblue )    /* gray shade */
  401.         gx_render_gray(mred, pdc, pgs);
  402.     else
  403.         gx_render_rgb(mred, mgreen, mblue, pdc, pgs);
  404. }
  405.  
  406. private void
  407. cmap_rgb_to_gray(frac r, frac g, frac b, gx_device_color *pdc,
  408.   const gs_state *pgs)
  409. {    (*pgs->cmap_procs->map_gray)(color_rgb_to_gray(r, g, b, pgs), pdc, pgs);
  410. }
  411.  
  412. private void
  413. cmap_rgb_to_cmyk(frac r, frac g, frac b, gx_device_color *pdc,
  414.   const gs_state *pgs)
  415. {    frac cmyk[4];
  416.     color_rgb_to_cmyk(r, g, b, pgs, cmyk);
  417.     (*pgs->cmap_procs->map_cmyk)(cmyk[0], cmyk[1], cmyk[2], cmyk[3], pdc, pgs);
  418. }
  419.  
  420. /* Render CMYK color. */
  421.  
  422. /* See above under RGB for why we can't use a shortcut for gray. */
  423.  
  424. private void
  425. cmap_cmyk_direct(frac c, frac m, frac y, frac k, gx_device_color *pdc,
  426.   const gs_state *pgs)
  427. {    gx_device *dev = gs_currentdevice(pgs);
  428.     frac mcyan = gx_map_color_frac(pgs, c, red);
  429.     frac mmagenta = gx_map_color_frac(pgs, m, green);
  430.     frac myellow = gx_map_color_frac(pgs, y, blue);
  431.     frac mblack = gx_map_color_frac(pgs, k, gray);
  432.     /* We make a test for direct vs. halftoned, rather than */
  433.     /* duplicating most of the code of this procedure. */
  434.     if ( dev->color_info.max_rgb >= 31 )
  435.     {    gx_color_index color =
  436.             (*dev->procs->map_cmyk_color)(dev,
  437.                 frac2cv(mcyan), frac2cv(mmagenta),
  438.                 frac2cv(myellow), frac2cv(mblack));
  439.         if ( color != gx_no_color_index )
  440.         {    color_set_pure(pdc, color);
  441.             return;
  442.         }
  443.     }
  444.     /* CMYK halftones are not implemented yet. */
  445.     {    frac rgb[3];
  446.         color_cmyk_to_rgb(c, m, y, k, pgs, rgb);
  447.         cmap_rgb_halftoned(rgb[0], rgb[1], rgb[2], pdc, pgs);
  448.     }
  449. }
  450.  
  451. private void
  452. cmap_cmyk_to_gray(frac c, frac m, frac y, frac k, gx_device_color *pdc, const gs_state *pgs)
  453. {    (*pgs->cmap_procs->map_gray)(color_cmyk_to_gray(c, m, y, k, pgs), pdc, pgs);
  454. }
  455.  
  456. private void
  457. cmap_cmyk_to_rgb(frac c, frac m, frac y, frac k, gx_device_color *pdc, const gs_state *pgs)
  458. {    frac rgb[3];
  459.     color_cmyk_to_rgb(c, m, y, k, pgs, rgb);
  460.     (*pgs->cmap_procs->map_rgb)(rgb[0], rgb[1], rgb[2], pdc, pgs);
  461. }
  462.  
  463. /* ------ Transfer function mapping ------ */
  464.  
  465. /* Map a color fraction through a transfer map. */
  466. frac
  467. gx_color_frac_map(frac cv, const frac *values)
  468. {
  469. #define cp_frac_bits (frac_bits - log2_transfer_map_size)
  470.     int cmi = cv >> cp_frac_bits;
  471.     frac mv = values[cmi];
  472.     int rem, mdv;
  473.     /* Interpolate between two adjacent values if needed. */
  474.     rem = (cv & ((1 << cp_frac_bits) - 1)) - (cv >> (frac_bits - cp_frac_bits));
  475.     if ( rem == 0 ) return mv;
  476.     else if ( rem > 0 ) mdv = values[cmi + 1] - mv;
  477.     else mdv = mv - values[cmi - 1];
  478. #if arch_ints_are_short
  479.     /* Only use long multiplication if necessary. */
  480.     if ( mdv > 1 << (16 - cp_frac_bits) )
  481.         return mv + (uint)(((ulong)rem * mdv) >> cp_frac_bits);
  482. #endif
  483. #ifndef AMIGA
  484.     return mv + ((rem * mdv) >> cp_frac_bits);
  485. #else
  486.     return ((frac)(mv + ((rem * mdv) >> cp_frac_bits)));
  487. #endif
  488. #undef cp_frac_bits
  489. }
  490.  
  491. /* ------ Default device color mapping ------ */
  492.  
  493. gx_color_index
  494. gx_default_map_rgb_color(gx_device *dev,
  495.   gx_color_value r, gx_color_value g, gx_color_value b)
  496. {    /* Map values >= 1/2 to 1, < 1/2 to 0. */
  497.     return ((r | g | b) > gx_max_color_value / 2 ?
  498.         (gx_color_index)1 : (gx_color_index)0);
  499. }
  500.  
  501. int
  502. gx_default_map_color_rgb(gx_device *dev, gx_color_index color,
  503.   gx_color_value prgb[3])
  504. {    /* Map 1 to max_value, 0 to 0. */
  505.     prgb[0] = prgb[1] = prgb[2] = -(gx_color_value)color;
  506.     return 0;
  507. }
  508.  
  509. gx_color_index
  510. gx_default_map_cmyk_color(gx_device *dev,
  511.   gx_color_value c, gx_color_value m, gx_color_value y, gx_color_value k)
  512. {    /* Convert to RGB */
  513.     frac rgb[3];
  514.     color_cmyk_to_rgb(cv2frac(c), cv2frac(m), cv2frac(y), cv2frac(k),
  515.               NULL, rgb);
  516.     return (*dev->procs->map_rgb_color)(dev,
  517.         frac2cv(rgb[0]), frac2cv(rgb[1]), frac2cv(rgb[2]));
  518. }
  519.